<?php
/*****************************************************
 * File name: Admin.php
 * Create date: 2019/03/28
 * Author: liuyue
 * Description: 后台管理模块cgi
 *****************************************************/

namespace Ctrl;

use Lib;
use Model\VersionModel;
use Model\SeasonModel;
class Admin extends Lib\Base\Ctrl
{
    protected $icon;
    private $versionModel;

    public function __construct()
    {
        //校验管理员权限
        $roleService = new Lib\Paas\Role();
        $checkAdmin = $roleService->getRoleInfo();
//        if ($checkAdmin['role'] != ROLE_ID) {
//            die('抱歉！您没有访问权限');
//        }
//        if (!in_array(MODULE_ID, $checkAdmin['moduleID']) ) {
//            die('抱歉！您没有访问权限');
//        }
        $this->icon = "/Public/Static/Icon/";
        $this->versionModel = new VersionModel();
        $this->seasonModel = new SeasonModel();
    }

    /**
     * 后台入口
     */
    public function index()
    {
        //获取用户信息
        $login = new Lib\Paas\Login();
        $loginInfo = $login->getLoginInfo();
        $this->assign("adminName",$loginInfo['name']);

        $this->display('Admin/Main/index');
    }

    public function navs()
    {
        $navs = [];

        //获取当前版本信息
        $resVersion = $this->versionModel->getCurrentVersion();
        $resSeason = $this->seasonModel->getCurrentSeason();


        /*菜单开始*/
        $item['title'] = "版本".$resVersion['versionNumber'].'季度'.$resSeason['seasonNumber'];
        $item['img'] = "";
        $item['icon'] = "";
        $item['href'] = "";
        $item['spread'] = false;
        $item['children'] = [];



        $children['title'] = "种族";
        $children['img'] = $this->icon."hero.png";
        $children['icon'] = "";
        $children['href'] = U('Race/index');
        $children['spread'] = false;
        $item['children'][] = $children;

        $children['title'] = "职业";
        $children['img'] = $this->icon."hero.png";
        $children['icon'] = "";
        $children['href'] = U('Job/index');
        $children['spread'] = false;
        $item['children'][] = $children;


        $children['title'] = "英雄";
        $children['img'] = $this->icon."hero.png";
        $children['icon'] = "";
        $children['href'] = U('Hero/index');
        $children['spread'] = false;
        $item['children'][] = $children;

        $children['title'] = "棋子";
        $children['img'] = $this->icon."hero.png";
        $children['icon'] = "";
        $children['href'] = U('Chess/index');
        $children['spread'] = false;
        $item['children'][] = $children;




        $children['title'] = "道具";
        $children['img'] = $this->icon."item.png";
        $children['icon'] = "";
        $children['href'] =  U('Equip/index');
        $children['spread'] = false;
        $item['children'][] = $children;





        $children['title'] = "版本和季度";
        $children['img'] = $this->icon."6.png";
        $children['icon'] = "";
        $children['href'] = U('Main/versionAndSeason');
        $children['spread'] = false;
        $item['children'][] = $children;

        $navs[] = $item;
//
        /*菜单开始*/
        $item['title'] = "操作记录";
        $item['img'] = "";
        $item['icon'] = "";
        $item['href'] = U('Operation/index');
        $item['spread'] = false;
        $item['children'] = [];

        $navs[] = $item;
        /*菜单结束*/
        $this->ajaxReturn($navs);
    }
}